<?php
//PLUGIN type=action
//PLUGIN name=group.edit
//PLUGIN desc=Enables you to add modules to your pages
//PLUGIN group=native

$perm_file = _SETTINGSPATH_ . "/permlist.ser";

if (file_exists($perm_file))
{
    $permlist = unserialize(file_get_contents($perm_file));
}
if(!is_array($permlist)){
    $permlist = array(
        "modules" => array(),
        "pages" => array(),
        "system" => array()
    );
}


if (!is_array($modules = glob(_MODULEPATH_ . '/*/')))
    $modules = array();

foreach ($modules as $m)
{
    $name = substr(strstr($m,"/!sys/modules/"),14,-1);
    if(!array_key_exists($name,$permlist["modules"])){
        $p = &$permlist['modules'][$name];
        switch($m){
            case (file_exists($m."config.php")):
              $p["config"] = true;
            case (file_exists($m."module.php")):
              $p["view"] = true;
            case (file_exists($m."editor.php")):
              $p["edit"] = true;
        }
        if(count($p)<1) unset($permlist['modules'][$name]);
    }
}
if (!is_array($plugins = glob(__ADMIN_DIR__ . '/plugins/action.*')))
    $plugins = array();
foreach ($plugins as $m)
{
    $name = substr(strstr($m,"/action."),8,-4);
    if(!array_key_exists($name,$permlist["system"])){
       $permlist['system'][$name]["use"] = false;
    }
}

file_put_contents($perm_file, serialize($permlist));

return "Hello world!";
?>
